import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:chat_app_project/components/image_viewer_page.dart';
import 'package:chat_app_project/models/msg.dart';
import 'package:flutter/material.dart';
import 'package:wukongimfluttersdk/model/wk_image_content.dart';
import 'package:wukongimfluttersdk/type/const.dart';

import '../../../models/const.dart';

class ImageMessage extends StatelessWidget {
  const ImageMessage({super.key, required this.message});

  final UIMsg message;

  double getMin(double b,BuildContext context){
    var a = MediaQuery.of(context).size.width * 0.45;
    if(a > b){
      return b;
    }
    return a;
  }

  @override
  Widget build(BuildContext context) {
    var wkMsg = message.wkMsg;
    var content = wkMsg.messageContent as WKImageContent;
    var isSender = wkMsg.fromUID == UserInfo.uid;
    debugPrint("wkMsg.status ${wkMsg.status}");
    return SizedBox(
        width: getMin(content.width.toDouble(), context),
        child: ClipRRect(
          borderRadius: BorderRadius.circular(8),
          child: GestureDetector(
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(
                  builder: (context) =>
                      ImageViewerPage(imageItems: [content.url])));
            },
            child: wkMsg.status == WKSendMsgResult.sendLoading
                ? Image.file(File(content.localPath))
                : CachedNetworkImage(
                     imageUrl: content.url,
                    // width: content.width.toDouble() ,
                    // height: content.height.toDouble(),
                    // fit: BoxFit.contain,
                  ),
          ),
        ));
  }
}
